home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume15 / kbmap / part01 next >
Encoding:
Text File  |  1990-10-14  |  36.1 KB  |  1,219 lines

  1. Newsgroups: comp.sources.misc
  2. X-UNIX-From: tony@ajfcal.cpsc.ucalgary.ca
  3. from: Tony Field <tony@ajfcal.cpsc.ucalgary.ca>
  4. subject: v15i078: kbmap source posting
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 15, Issue 78
  8. Submitted-by: Tony Field <tony@ajfcal.cpsc.ucalgary.ca>
  9. Archive-name: kbmap/part01
  10.  
  11. "kbmap" is an attempt to modify the AT&T Unix SysV/386 v3.2.2 system
  12. keyboard map. In particular, it can make minor adjustments to the
  13. system's keyboard scancodes to allow all "alt" keys to be used in the
  14. gnuemacs meta-commands. Aside from the system default and emacs maps, any
  15. keyboard map may be manually added to a "kbmap.table" file.
  16.  
  17. tony...
  18.   --------------------------------------------------------------------
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of shell archive."
  27. # Contents:  Readme kbmap.doc kbmap.1 kbmap.c Makefile
  28. # Wrapped by ajf@ajfcal on Sun Sep  9 18:53:46 1990
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f 'Readme' -a "${1}" != "-c" ; then 
  31.   echo shar: Will not clobber existing file \"'Readme'\"
  32. else
  33. echo shar: Extracting \"'Readme'\" \(1425 characters\)
  34. sed "s/^X//" >'Readme' <<'END_OF_FILE'
  35. X"kbmap" is an attempt to modify the AT&T Unix SysV/386 v3.2.2 system
  36. Xkeyboard map. In particular, it can make minor adjustments to the
  37. Xsystem's keyboard scancodes to allow all "alt" keys to be used in the
  38. Xgnuemacs meta-mode. Aside from the system default and emacs maps, any
  39. Xkeyboard map may be manually added to a "kbmap.table" file.
  40. X
  41. XTwo gnuemacs mappings are available: one that uses the ALT key to
  42. Xgenerate 8th bit set letters (<letter>|0x080) and another that follows
  43. XAT&T conventions such that the ALT key generates (<esc>N<letter>).
  44. X
  45. XNote that X11R2 will not recognize 8th bit set letters. If you have
  46. XX11R2 and ascii console users, then you should use the 'conventional
  47. X<esc>N<letter> mapping - even so, X11 uses it's own keyboard mapping
  48. Xwhich is similar to, but not the same as, the default map. X11 will NOT
  49. Xrecognize the mappings provided by kbmap. The differences are mostly in
  50. Xthe assignment of the keyboard arrow keys to become Dec'ish in nature.
  51. X
  52. XTo add to the havoc, vtlmgr also takes liberties and twiddles the
  53. Xkeyboard mapping.
  54. X
  55. Xkbmap works on AT&T Unix SysV/386 v3.2.2. It may or may not work on other
  56. Xversions of unix.
  57. X
  58. X
  59. XINSTALLATION:     Modify the Makefile to select your compiler, default
  60. X                  bin directory and default map table name.
  61. X                  
  62. X                  Then:        make all
  63. X                  
  64. X                  Then:        read the SETUP section "kbmap.doc" to install
  65. X
  66. Xtony...
  67. END_OF_FILE
  68. if test 1425 -ne `wc -c <'Readme'`; then
  69.     echo shar: \"'Readme'\" unpacked with wrong size!
  70. fi
  71. # end of 'Readme'
  72. fi
  73. if test -f 'kbmap.doc' -a "${1}" != "-c" ; then 
  74.   echo shar: Will not clobber existing file \"'kbmap.doc'\"
  75. else
  76. echo shar: Extracting \"'kbmap.doc'\" \(6313 characters\)
  77. sed "s/^X//" >'kbmap.doc' <<'END_OF_FILE'
  78. X
  79. X
  80. X     KBMAP(1)               Unix System V              KBMAP(1)
  81. X
  82. X
  83. X     NAME
  84. X      kbmap    - change keyboard scancode mapping
  85. X
  86. X     SYNOPSIS
  87. X      kbmap    [-i] [-1] [-g] [-n n] [d] [-e] [-m] [-a] [-t /dev/xxx] [file]
  88. X         -i     = show    index of available maps
  89. X         -q     = query which table is    currently in use
  90. X         -g     = generate a key map table
  91. X         -n n     = set keyboard    to map 'n' mapping
  92. X         -d     = set keyboard    to normal mapping
  93. X         -e     = set keyboard    to <esc>N emacs    mapping
  94. X         -m     = set keyboard    to meta    (8bit) emacs mapping
  95. X         -a     = do not convert <alt><ctl> and <alt><shf><ctl>
  96. X         -t /dev/xxx = apply map to this device
  97. X         file     = use specified key map file
  98. X
  99. X
  100. X     DESCRIPTION
  101. X      Kbmap    reads a    text file containg keyboard mapping
  102. X      information and set the keyboard to the selected mapping.
  103. X
  104. X      Kbmap    can create a standard mapping file
  105. X      (/local/lib/kbmap.table) that    contains the system default
  106. X      mapping as well as an    two different emacs mapping that allow
  107. X      alt to be used as the    emacs meta-key.    Other keyboard
  108. X      mappings may be manually added to the    kbmap.table file.
  109. X
  110. X      Only root may    use this programme from    the console.
  111. X
  112. X      It cannot be run from    an rc2.d/xxx file or cron.
  113. X
  114. X      True META mapping (with 8th bit set) set with    -m cannot be
  115. X      used with X11R2 (X11 does not    use the    standard keyboard
  116. X      maps).  If you use X11R2 and the ascii console environments,
  117. X      the -e option    should be used for emacs mapping simply    to
  118. X      ensure that the .emacs files can be used in either mode
  119. X      without change.
  120. X
  121. X
  122. X     OPTIONS
  123. X      -i   Show index of maps recorded in map.table.  The map
  124. X           numbers may be used with    the -n option to select    maps
  125. X           by number.
  126. X
  127. X
  128. X      -q   The query option    causes the current scancode table in
  129. X           the kernal to be    compared to all    of the tables in
  130. X           kbmap.table. If a match is found, the name of the
  131. X           currently active    table is printed.
  132. X
  133. X           If vtlmgr is used, then an attempt is made to identify
  134. X           which keyboard map is in    use in spite of    modifications
  135. X
  136. X
  137. X     Page 1                          (printed 9/9/90)
  138. X
  139. X
  140. X     KBMAP(1)               Unix System V              KBMAP(1)
  141. X
  142. X
  143. X           made by vtlmgr.
  144. X
  145. X
  146. X      -g   Generate    a new keyboard map file.  The systems current
  147. X           keyboard    map is retrieved and written to    the
  148. X           kbmap.table file.  Two mapping files for    emacs are
  149. X           appended.  The system's keyboard    map is not updated.
  150. X
  151. X
  152. X      file Select file to be the generated keyboard    map file,
  153. X           usually kbmap.table.
  154. X
  155. X
  156. X      -d   Select the system default map from kbmap.table and
  157. X           update the system's current keyboard map.
  158. X
  159. X
  160. X      -e   Select the emacs    default    map from kbmap.table and
  161. X           update the system's current keyboard map.  Emacs    users
  162. X           may use alt as the meta-key.   If you press the alt key
  163. X           and a letter together, the letter is generated with the
  164. X           escape sequence <esc>N<letter>.
  165. X
  166. X           If this mapping is used,    the .emacs files should
  167. X           contain the following:
  168. X
  169. X            (define-key    global-map "\M-N" 'ESC-prefix)
  170. X
  171. X           to enable the recognition of the    new escape sequences.
  172. X
  173. X           The only    significant change to the AT&T standard
  174. X           keyboard    mapping    is that    the <alt><del> meta is enabled
  175. X           to allow    backward-kill-word.
  176. X
  177. X
  178. X      -m   Select the emacs    meta-key 8th bit map from kbmap.table
  179. X           and update the system's current keyboard    map.  Emacs
  180. X           users may use alt as the    meta-key.   If you press the
  181. X           alt key and a letter together, the letter is generated
  182. X           as <letter> | 0x080.
  183. X
  184. X           If this mapping is used,    the .emacs files should
  185. X           contain the following:
  186. X
  187. X            (setq meta-flag t)
  188. X
  189. X           to enable the recognition 8th bit set meta characters.
  190. X
  191. X           X11R2 will not recognize    8th bit    set characters.     As a
  192. X           result, the -m option should not    be used    if you intend
  193. X           to run emacs with X11R2.
  194. X
  195. X
  196. X     Page 2                          (printed 9/9/90)
  197. X
  198. X
  199. X     KBMAP(1)               Unix System V              KBMAP(1)
  200. X
  201. X
  202. X      -n i Select the i'th map from    the kbmap.table    file and
  203. X           update the system.  The system default map is 0 and the
  204. X           emacs map is 1 or 2. If other keyboard maps are added
  205. X           to the end of the kbmap.table file, then    they may be
  206. X           accessed    by number.
  207. X
  208. X
  209. X      -a   Normally, kbmap extends mapping for <alt><ctl> and
  210. X           <alt><shif><ctl>    keys.  If the -a option    is used, these
  211. X           will be disabled.
  212. X
  213. X           If the -a is used, then the gnuemacs C-M- sequences
  214. X           (such as    C-M-s (isearch-forward-regexp))    cannot use the
  215. X           <alt><ctl><letter> combinations.     Instead, the <esc> +
  216. X           <ctl><letter> sequence is used.
  217. X
  218. X
  219. X      -t /dev/xxx
  220. X           Use the specified device    rather than stdin.  (This is
  221. X           not really useful.)
  222. X
  223. X
  224. X     SETUP
  225. X      Create a basic keyboard mapping file that contains both the
  226. X      standard map and the emacs meta-key map:
  227. X
  228. X            kbmap -g kbmap.table
  229. X
  230. X      The current keyboard table is    fetched. The current mapping
  231. X      information as described in the keymap_t structure is
  232. X      written to disk file kbmap.table. The    meta-conversion    for
  233. X      emacs    is performed on    the structure and the resulting
  234. X      information is appended to kbmap.table. The new information
  235. X      is NOT updated in the    kernal.
  236. X
  237. X      Copy kbmap.table to /local/lib/kbmap.table (or other file as
  238. X      specified during system compilation.)          Any keyboard
  239. X      mapping may now be selected (using the default file
  240. X      /local/lib/kbmap.table):
  241. X
  242. X        kbmap -d    = select default map
  243. X        kbmap -e    = select emacs <esc>N<letter> map
  244. X        kbmap -m    = select emacs <letter>|0x080 meta map
  245. X
  246. X      Alternatively, the key mapping may be    selected by number:
  247. X
  248. X        kbmap -m 0  = select map 0 (default map)
  249. X        kbmap -m 1  = select map 1 (emacs <letter>|0x08    meta-map)
  250. X        kbmap -m 2  = select map 2 (normal <esc>N<letter> emacs)
  251. X        kbmap -m 3  = select map 3 (your additional)
  252. X           etc.
  253. X
  254. X
  255. X     Page 3                          (printed 9/9/90)
  256. X
  257. X
  258. X     KBMAP(1)               Unix System V              KBMAP(1)
  259. X
  260. X
  261. X     NOTES
  262. X      The changes made by kbmap are    reset to system    defaults
  263. X      whenever the system is booted.  If permanent changes are
  264. X      needed, then the system default mapping in
  265. X      /etc/conf/pack.d/kd/Driver.o should be "zapped" with the
  266. X      appropriate table and    the kernal rebuilt.
  267. X
  268. X
  269. X     FILES
  270. X      /local/lib/kbmap.table
  271. X
  272. X
  273. X     AUTHOR
  274. X      Tony Field (tony%ajfcal@cpsc.ucalgary.ca, tony@ajfcal)
  275. X
  276. X
  277. X     Page 4                          (printed 9/9/90)
  278. X
  279. X
  280. END_OF_FILE
  281. if test 6313 -ne `wc -c <'kbmap.doc'`; then
  282.     echo shar: \"'kbmap.doc'\" unpacked with wrong size!
  283. fi
  284. # end of 'kbmap.doc'
  285. fi
  286. if test -f 'kbmap.1' -a "${1}" != "-c" ; then 
  287.   echo shar: Will not clobber existing file \"'kbmap.1'\"
  288. else
  289. echo shar: Extracting \"'kbmap.1'\" \(5749 characters\)
  290. sed "s/^X//" >'kbmap.1' <<'END_OF_FILE'
  291. X.TH KBMAP 1 ""
  292. X.SH NAME
  293. Xkbmap \- change keyboard scancode mapping
  294. X.SH SYNOPSIS
  295. X.nf
  296. X
  297. Xkbmap [-i] [-1] [-g] [-n n] [d] [-e] [-m] [-a] [-t /dev/xxx] [file]
  298. X       -i      = show index of available maps
  299. X       -q      = query which table is currently in use
  300. X       -g      = generate a key map table
  301. X       -n n    = set keyboard to map 'n' mapping
  302. X       -d      = set keyboard to normal mapping
  303. X       -e      = set keyboard to <esc>N emacs mapping
  304. X       -m      = set keyboard to meta (8bit) emacs mapping
  305. X       -a      = do not convert <alt><ctl> and <alt><shf><ctl>
  306. X       -t /dev/xxx = apply map to this device
  307. X       file    = use specified key map file
  308. X.fi
  309. X
  310. X.SH DESCRIPTION
  311. X
  312. XKbmap reads a text file containg keyboard mapping information and
  313. Xset the keyboard to the selected mapping.
  314. X
  315. XKbmap can create a standard mapping file (/local/lib/kbmap.table)
  316. Xthat contains the system default mapping as well as an two different
  317. Xemacs mapping that allow
  318. X.B alt
  319. Xto be used as the emacs meta-key. Other
  320. Xkeyboard mappings may be manually added to the kbmap.table file.
  321. X
  322. XOnly root may use this programme from the console.
  323. X
  324. XIt cannot be run from an rc2.d/xxx file or cron.
  325. X
  326. XTrue META mapping (with 8th bit set) set with -m cannot be used with 
  327. XX11R2 (X11 does not use the standard keyboard maps).  If you use
  328. XX11R2 and the ascii console environments, the 
  329. X.B \-e
  330. Xoption should be used for emacs mapping simply to ensure that
  331. Xthe .emacs files can be used in either mode without change.
  332. X
  333. X.SH OPTIONS
  334. X.TP
  335. X.B \-i
  336. XShow index of maps recorded in map.table.  The map numbers
  337. Xmay be used with the 
  338. X.B \-n
  339. Xoption to select maps by number.
  340. X
  341. X.TP
  342. X.B \-q
  343. XThe query option causes the current scancode table
  344. Xin the kernal to be compared to all of the tables in
  345. X.B kbmap.table.
  346. XIf a match is found, the name of the currently
  347. Xactive table is printed.
  348. X
  349. XIf vtlmgr is used, then an attempt is made to
  350. Xidentify which keyboard map is in use in spite
  351. Xof modifications made by vtlmgr.
  352. X
  353. X.TP
  354. X.B \-g
  355. XGenerate a new keyboard map file.  The systems current keyboard
  356. Xmap is retrieved and written to the
  357. X.B kbmap.table
  358. Xfile.  Two mapping files for emacs are appended.
  359. XThe system's keyboard map is not updated.
  360. X
  361. X.TP
  362. X.B file
  363. XSelect
  364. X.B file
  365. Xto be the generated keyboard map file, usually
  366. X.B kbmap.table.
  367. X
  368. X.TP
  369. X.B \-d
  370. XSelect the system default map from
  371. X.B kbmap.table
  372. Xand update the system's current keyboard map.
  373. X
  374. X.TP
  375. X.B \-e
  376. XSelect the emacs default map from
  377. X.B kbmap.table
  378. Xand update the system's current keyboard map.  Emacs
  379. Xusers may use
  380. X.B alt
  381. Xas the meta-key.   If you press
  382. Xthe
  383. X.B alt
  384. Xkey and a letter together, the letter is generated with
  385. Xthe escape sequence <esc>N<letter>.
  386. X
  387. XIf this mapping is used, the \.emacs files should contain
  388. Xthe following:
  389. X.nf
  390. X
  391. X     (define-key global-map "\\M-N" 'ESC-prefix)
  392. X.fi
  393. X
  394. Xto enable the recognition of the new escape sequences.
  395. X
  396. XThe only significant change to the AT&T standard
  397. Xkeyboard mapping is that the <alt><del> meta is
  398. Xenabled to allow backward-kill-word.
  399. X
  400. X.TP
  401. X.B \-m
  402. XSelect the emacs meta-key 8th bit map from
  403. X.B kbmap.table
  404. Xand update the system's current keyboard map.  Emacs
  405. Xusers may use
  406. X.B alt
  407. Xas the meta-key.   If you press
  408. Xthe
  409. X.B alt
  410. Xkey and a letter together, the letter is generated
  411. Xas <letter> | 0x080.
  412. X
  413. XIf this mapping is used, the \.emacs files should contain
  414. Xthe following:
  415. X.nf
  416. X
  417. X     (setq meta-flag t)
  418. X.fi
  419. X
  420. Xto enable the recognition 8th bit set meta characters.
  421. X
  422. XX11R2 will not recognize 8th bit set characters.  As a result,
  423. Xthe
  424. X.B \-m
  425. Xoption should not be used if you intend to run emacs with
  426. XX11R2.
  427. X
  428. X.TP
  429. X.B \-n i
  430. XSelect the 
  431. X.B i'th
  432. Xmap from the
  433. X.B kbmap.table
  434. Xfile and update the system.  The system default map is
  435. X.B 0
  436. Xand the emacs map is
  437. X.B 1
  438. Xor
  439. X.B 2.
  440. XIf other keyboard maps are added to the end of the
  441. X.B kbmap.table
  442. Xfile, then they may be accessed by number.
  443. X
  444. X.TP
  445. X.B \-a
  446. XNormally, kbmap extends mapping for <alt><ctl>
  447. Xand <alt><shif><ctl> keys.  If the
  448. X.B \-a
  449. Xoption is used, these will be disabled.
  450. X
  451. XIf the
  452. X.B \-a
  453. Xis used, then the gnuemacs
  454. XC-M- sequences (such as C-M-s (isearch-forward-regexp))
  455. Xcannot use the <alt><ctl><letter> combinations.  Instead,
  456. Xthe <esc> + <ctl><letter> sequence is used.
  457. X
  458. X.TP
  459. X.B \-t /dev/xxx
  460. XUse the specified device rather than stdin.
  461. X(This is not really useful.)
  462. X
  463. X.SH SETUP
  464. X
  465. XCreate a basic keyboard mapping file that contains both the
  466. Xstandard map and the emacs meta-key map:
  467. X
  468. X.nf
  469. X          kbmap -g kbmap.table
  470. X.fi
  471. X
  472. XThe current keyboard table is fetched. The current mapping
  473. Xinformation as described in the 
  474. X.B keymap_t
  475. Xstructure is written to
  476. Xdisk file 
  477. X.B kbmap.table.
  478. XThe meta-conversion for
  479. X.B emacs
  480. Xis performed on the structure and the resulting information is appended
  481. Xto 
  482. X.B kbmap.table.
  483. XThe new information is NOT updated in the kernal.
  484. X
  485. XCopy
  486. X.B kbmap.table
  487. Xto
  488. X.B \/local\/lib\/kbmap.table
  489. X(or other file as specified during system compilation.)
  490. X    
  491. XAny keyboard mapping may now be selected (using the default
  492. Xfile 
  493. X.B \/local\/lib\/kbmap.table):
  494. X
  495. X.nf
  496. X      kbmap -d    = select default map
  497. X      kbmap -e    = select emacs <esc>N<letter> map
  498. X      kbmap -m    = select emacs <letter>|0x080 meta map
  499. X.fi
  500. X
  501. XAlternatively, the key mapping may be selected by number:
  502. X.nf
  503. X
  504. X      kbmap -m 0  = select map 0 (default map)
  505. X      kbmap -m 1  = select map 1 (emacs <letter>|0x08 meta-map)
  506. X      kbmap -m 2  = select map 2 (normal <esc>N<letter> emacs)
  507. X      kbmap -m 3  = select map 3 (your additional)
  508. X         etc.
  509. X.fi
  510. X
  511. X.SH NOTES
  512. X
  513. XThe changes made by kbmap are reset to system defaults whenever
  514. Xthe system is booted.  If permanent changes are needed, then
  515. Xthe system default mapping in /etc/conf/pack.d/kd/Driver.o
  516. Xshould be "zapped" with the appropriate table and the kernal
  517. Xrebuilt.
  518. X
  519. X.SH FILES
  520. X
  521. X/local/lib/kbmap.table
  522. X
  523. X.SH AUTHOR
  524. X
  525. XTony Field (tony%ajfcal@cpsc.ucalgary.ca, tony@ajfcal)
  526. END_OF_FILE
  527. if test 5749 -ne `wc -c <'kbmap.1'`; then
  528.     echo shar: \"'kbmap.1'\" unpacked with wrong size!
  529. fi
  530. # end of 'kbmap.1'
  531. fi
  532. if test -f 'kbmap.c' -a "${1}" != "-c" ; then 
  533.   echo shar: Will not clobber existing file \"'kbmap.c'\"
  534. else
  535. echo shar: Extracting \"'kbmap.c'\" \(18744 characters\)
  536. sed "s/^X//" >'kbmap.c' <<'END_OF_FILE'
  537. X/* ta=4     tabs set at 4*/
  538. X/*
  539. X        kbmap.c
  540. X        
  541. X    Kbmap reads a text file containg keyboard mapping information and
  542. X    set the keyboard to the selected mapping.  It can also create
  543. X    a map file with the -g option.
  544. X
  545. X    Only root may use this programme from the console.
  546. X    It cannot be run from an rc2.d/xxx file or cron.
  547. X
  548. X    Then true-meta keys cannot be used with X11R2 - which uses its own map.
  549. X    VTLMGR tends to modify a couple of keys.  The -q option (query_map())
  550. X    tries to detect a vtlmgr modification.
  551. X
  552. X    This works for AT&T Unix 3.2.2 - other systems not tested.
  553. X
  554. XAUTHOR:    Tony Field    (tony%ajfcal@cpsc.ucalgary.ca)
  555. X
  556. XNOTES:
  557. X
  558. X  Structure of keyboard translation table (from /usr/include/sys/kd.h)
  559. X
  560. X    #define NUM_KEYS    256                    Maximum number of keys
  561. X    #define NUM_STATES    8                    Number of key states
  562. X    #pragma pack(2)
  563. X    typedef struct {
  564. X        short  n_keys ;                        Number of entries in table
  565. X        struct key_t {
  566. X            unsigned char map[NUM_STATES];    Key code for each state
  567. X            unsigned char spcl;                Bits marking states as special
  568. X            unsigned char flgs;                Flags
  569. X        } key[NUM_KEYS+1];                    One entry for each key
  570. X    } keymap_t;
  571. X
  572. X    (note: NUM_KEYS is specified as 256, however n_keys only
  573. X           describes 128 keys...  kbmap only updates the first
  574. X           128 keys.  The remainder are unmodified.)
  575. X
  576. X    Each key has 8 (NUM_STATES) possible scan states honoured if
  577. X    set in the "spcl" field:
  578. X
  579. X        spcl    map[i]
  580. X        bit 7     i=0        = normal
  581. X            6       1        = shifted
  582. X            5       2        = control
  583. X            4      3        = shift-control
  584. X            3       4        = alt
  585. X            2       5        = alt-shift
  586. X            1       6        = alt-control
  587. X            0       7        = alt-shift-control
  588. X    
  589. X    If the corresponding bit is set, then the feature is enabled. For
  590. X    example, if bit 3 is set, then the keyboard driver will translate
  591. X    the scan code into the "<esc>Nx" escape sequence. If the 3ed bit is
  592. X    NOT set, then the driver will use the character as specified in
  593. X    map[4] as the returned value.
  594. X
  595. X    The "flgs" field needs no modification: it allows the "numlok",
  596. X    "caploc" and "control" keys to be used with specific keys:
  597. X    
  598. X            0x8000        allow numlock
  599. X            0x4000        allow caps lock
  600. X            0x2000        allow control
  601. X            0x1000        locking is off
  602. X    
  603. X    At leaset that is what <sys/kd.h> indicates.  But that is not
  604. X    what is indicated in the actual dump of the tables...  Alphabetic
  605. X    characters contain 0x01, the numeric keypad contains 0x02, and
  606. X    verything else contains 0x00.  Oh well...  A more reasonable
  607. X    interpretation is that these meanings are assigned to the
  608. X    high order 4 bits of "spcl", but that is only a guess.
  609. X
  610. X    In addition, the default value for the map[4] entry for most codes
  611. X    that can be translated into the <esc>Nx sequence is 0x7d.
  612. X    The 7x numbers are used for function key translation.  They mean
  613. X    (of course i am guessing):
  614. X    
  615. X            7d    = use <esc>Nx        where 'x' is the un-alted value
  616. X            7e    = use <esc>Ox        of the scan code (funny that 7e
  617. X            7f    = use <esc>Lx        and 7f do not appear in the table
  618. X                                    nor are visible in keyboard(7))
  619. X    
  620. X    Conversion of the table to emacs "meta" bits is done as follows:
  621. X
  622. X        1.    read the entire keyboard mapping structure with ioctl().    
  623. X        2.    if the base key (map[0]) is between ' ' & 0x7f and not uppercase
  624. X                then remove bit 3 from the spcl field and
  625. X                set map[4] = map[0] | 0x80.  The creates the
  626. X                meta-mapping of the keys for lower case letters.
  627. X        3.    if the shifted key (map[1]) is between ' ' & 0x7f and the
  628. X                map[0] value is not an upper case character,
  629. X                then remove bit 2 from the spcl field and
  630. X                set map[5] = map[1] | 0x80.  The creates the
  631. X                meta-mapping of the keys for upper case letters.
  632. X        4.    write the new keyboard mapping with ioctl().
  633. X
  634. X    Similar conversion is make for the "normal" emacs <esc>N prefix
  635. X    sequence.  This requires forcing the 0x7d code into all <alt>x slots.
  636. X    
  637. X    The map structure contains map[0] entries for both lower and upper
  638. X    case letters.  The lower case entries "seem" to be the only ones
  639. X    used.  No explanation is offered for the upper case entries.
  640. X*/
  641. X
  642. X
  643. X#include <stdio.h>
  644. X#include <sys/types.h>
  645. X#include <sys/at_ansi.h>
  646. X#include <sys/kd.h>
  647. X#include <sys/ioctl.h>
  648. X#include <fcntl.h>
  649. X
  650. X/*    where does kbmap expect to find the default map table    */
  651. X
  652. X#ifndef DEFAULTMAP
  653. X#define DEFAULTMAP    "/local/lib/kbmap.table"
  654. X#endif
  655. X
  656. Xchar    progname[150];
  657. Xint        vtlmgr;
  658. X
  659. Xmain (argc, argv)
  660. Xint        argc;
  661. Xchar    *argv[];
  662. X{
  663. X    extern char *optarg;
  664. X    extern int    optind;
  665. X    int        c;
  666. X    int        select_map = -1;
  667. X    char    use_file[200];
  668. X    int        generate_file = 0;
  669. X    FILE    *use_fp, *open_file();
  670. X    char    tfile[100];
  671. X    int        tn = -1;
  672. X    int        index_only = 0;
  673. X    char    line[200];
  674. X    int        query_only = 0;
  675. X    int        option_count = 0;
  676. X    int        also_alt_ctl = 1;
  677. X        
  678. X    strcpy (progname, argv[0]);
  679. X    use_fp = NULL;
  680. X    use_file[0] = '\0';
  681. X    if (argc == 1  ||  strcmp (argv[1], "-") == 0  || strcmp (argv[1], "--") == 0)
  682. X        usage();
  683. X
  684. X    while ((c = getopt(argc, argv, "aqgin:dmet:-?")) != -1)
  685. X    {    option_count++;
  686. X        switch (c)
  687. X        {
  688. X        case 'a':    also_alt_ctl = 0;                    /*    disable  alt+ctl expansion */
  689. X                    break;
  690. X        case 'i':    index_only = 1;
  691. X                    break;
  692. X        case 'n':    select_map = atoi (optarg);            /*    select by number    */
  693. X                    break;
  694. X        case 'd':    select_map = 0;                        /*    select default = 0    */
  695. X                    if (use_file[0] == '\0')
  696. X                        strcpy (use_file, DEFAULTMAP);
  697. X                    break;
  698. X        case 'e':    select_map = 2;                        /*    select emacs = 2    */
  699. X                    if (use_file[0] == '\0')
  700. X                        strcpy (use_file, DEFAULTMAP);
  701. X                    break;
  702. X        case 'm':    select_map = 1;                        /*    select emacs = 1 (meta) */
  703. X                    if (use_file[0] == '\0')
  704. X                        strcpy (use_file, DEFAULTMAP);
  705. X                    break;
  706. X        case 't':    strcpy (tfile, optarg);                /*    use terminal at /dev/xxxx */
  707. X                    if ((tn = open (tfile, O_RDWR)) < 0)
  708. X                    {    fprintf (stderr, "%s: Cannot open %s\n", progname, tfile);
  709. X                        exit (1);
  710. X                    }
  711. X                    break;
  712. X        case 'q':    query_only = 1;
  713. X                    break;
  714. X        case 'g':    generate_file = 1;                    /*    generate map file    */
  715. X                    if (use_file[0] == '\0')
  716. X                        strcpy (use_file, DEFAULTMAP);
  717. X                    break;
  718. X
  719. X        default:    usage ();
  720. X        }
  721. X    }
  722. X    if (optind < argc)
  723. X    {    strcpy (use_file, argv[optind]);            /*    specify map file    */
  724. X        if (option_count == 0)
  725. X            index_only = 1;
  726. X    }
  727. X
  728. X    if (tn < 1)
  729. X        tn = 0;
  730. X
  731. X    if (index_only)                                    /*    show index of maps    */
  732. X    {    use_fp = open_file (use_file, "r");
  733. X        c = 0;
  734. X        while (fgets (line, 190, use_fp) != NULL)
  735. X            if (strncmp (line, "...", 3) == 0)
  736. X                printf ("map %d = %s", c++, line + 3);
  737. X        fclose (use_fp);
  738. X        exit (0);
  739. X    }        
  740. X    
  741. X    if (query_only)                                    /*    which map is in use    */
  742. X    {    use_fp = open_file (use_file, "r");
  743. X        if (query_map (use_fp) == 0)
  744. X            printf ("current map is not in %s\n", use_file);
  745. X        exit (0);
  746. X    }
  747. X
  748. X    if (generate_file)                                /*    create new kbmap.table file */
  749. X    {    if (use_file[0])
  750. X        {    use_fp = open_file (use_file, "w");
  751. X            create_table (use_fp, tn, also_alt_ctl);
  752. X            fclose (use_fp);
  753. X        }
  754. X        else
  755. X            create_table (stdout, tn, also_alt_ctl);
  756. X    }        
  757. X
  758. X    if (select_map >= 0)
  759. X    {    use_fp = open_file (use_file, "r");
  760. X        update_map (use_fp, select_map);
  761. X        fclose (use_fp);
  762. X    }        
  763. X
  764. X    exit (0);
  765. X}
  766. X
  767. X/****************************************************************************
  768. X*    create_table (fp)                                                        *
  769. X*    Get the existing keyboard mapping structure and write to file.            *
  770. X*    Translate all alt and alt-shift keys to the meta-mapping.                *
  771. X*    Write the meta-mapping structure to disk file.                            *
  772. X****************************************************************************/
  773. X
  774. Xcreate_table (fp, tn, also_alt_ctl)
  775. XFILE *fp;            /*    file containing the keyboard maps                */
  776. Xint     tn;
  777. Xint     also_alt_ctl;    /*    convert ALT/CTL and ALT/SHIFT/CTL as well?        */
  778. X{
  779. X    int    i, j, cb, cs;
  780. X    keymap_t kt;
  781. X    char    title[200];
  782. X
  783. X    /*    get existing mapping    */
  784. X        
  785. X    if (ioctl (tn, GIO_KEYMAP, &kt))
  786. X        ioctl_failure ('r');
  787. X
  788. X    /*     write the existing mapping to the disk file
  789. X
  790. X        some potentiall useful keyboard scan numbers:
  791. X    
  792. X            1    esc
  793. X            14    bs
  794. X            15    tab
  795. X            28    cr
  796. X            83    del
  797. X            116    cr
  798. X            119    break
  799. X            121    del
  800. X
  801. X        For example, if scan code 1 (esc) is specifically selected,
  802. X        then the <ALT><ESC> combination becomes available.  This is
  803. X        not done because double-striking <esc> is quite easy.
  804. X
  805. X        It might be useful to force full alt-decoding for cr and tab.
  806. X        Emacs would recognize such sequences by default (see comments
  807. X        in the code to make this modification)
  808. X        
  809. X        The variable sequence is:
  810. X      char scan scpl flgs NORMAL SHIFT CTRL SHFCTL ALT ALTSHF ALTCTL ALTSHFCTL
  811. X    */
  812. X
  813. X    header (fp, "system default keyboard mapping", -1);
  814. X    for (i = 0;  i < kt.n_keys;  i++)
  815. X    {
  816. X        cb = kt.key[i].map[0];
  817. X        cs = kt.key[i].map[1];
  818. X        fprintf (fp, "%c%c %3d   %02x   %02x", 
  819. X                cb > ' ' &&  cb < 127 ? cb : ' ',
  820. X                cs > ' ' &&  cs < 127 &&  cs != cb ? cs : ' ',
  821. X                i, 
  822. X                kt.key[i].spcl & 0x0ff, 
  823. X                kt.key[i].flgs & 0x0ff);
  824. X        for (j = 0;  j < NUM_STATES;  j++)
  825. X            fprintf (fp, "   %02x", kt.key[i].map[j]);
  826. X        fprintf (fp, "\n");
  827. X    }
  828. X    
  829. X    /*    convert the existing mapping to emacs-meta (8th bit set) conventions
  830. X        and write to file
  831. X    */    
  832. X    
  833. X    fprintf (fp, "\n\n");
  834. X    strcpy (title, "emacs 8th bit set (<letter>|0x080) meta mapping");
  835. X    header (fp, title, also_alt_ctl);
  836. X    for (i = 0;  i < kt.n_keys;  i++)
  837. X    {
  838. X        cb = kt.key[i].map[NORMAL];            /*    base char        */
  839. X        cs = kt.key[i].map[SHIFT];            /*    shifted char    */
  840. X
  841. X        if (1)                                /*    things to ignore e,g,  (i == 121) */
  842. X        {
  843. X            /*    convert ALT key to meta. */
  844. X
  845. X            /*    add the following the various "if" statements below
  846. X                to enable full conversion of \t and \n:
  847. X            
  848. X                    ||  (i == 15)  ||  (i == 28)
  849. X            */
  850. X            if ((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb <= 127))
  851. X            {    kt.key[i].map[ALT] = (kt.key[i].map[NORMAL] | 0x080);
  852. X                kt.key[i].spcl &= 0x0f7;
  853. X            }
  854. X
  855. X            /*    convert ALT-CTRL key to meta. (dont include <alt><ctl><del> */
  856. X    
  857. X            if (also_alt_ctl  
  858. X                    &&  ((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb < 127)))
  859. X            {    kt.key[i].map[ALTCTL] = (kt.key[i].map[CTRL] | 0x080);
  860. X                kt.key[i].spcl &= 0x0fd;
  861. X            }
  862. X
  863. X            /* convert ALT-SHIFT to meta */
  864. X
  865. X            if (((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb <= 127))
  866. X                    &&  (cs >= ' '  &&  cs <= 127))
  867. X            {    kt.key[i].map[ALTSHF] = (kt.key[i].map[SHIFT] | 0x080);
  868. X                kt.key[i].spcl &= 0x0fb;
  869. X            }
  870. X        
  871. X            /* convert ALT-SHIFT-CTL to meta */
  872. X
  873. X            if (also_alt_ctl
  874. X                    &&   ((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb <= 127))
  875. X                    &&  (cs >= ' '  &&  cs <= 127))
  876. X            {    kt.key[i].map[ALTSHFCTL] = (kt.key[i].map[SHFCTL] | 0x080);
  877. X                kt.key[i].spcl &= 0x0fe;
  878. X            }
  879. X        }
  880. X        fprintf (fp, "%c%c %3d   %02x   %02x", 
  881. X                cb > ' ' &&  cb < 127 ? cb : ' ',
  882. X                cs > ' ' &&  cs < 127 &&  cs != cb ? cs : ' ',
  883. X                i, 
  884. X                kt.key[i].spcl & 0x0ff, 
  885. X                kt.key[i].flgs & 0x0ff);
  886. X        for (j = 0;  j < NUM_STATES;  j++)
  887. X            fprintf (fp, "   %02x", kt.key[i].map[j]);
  888. X        fprintf (fp, "\n");
  889. X    }
  890. X
  891. X    /*    re-get existing mapping    to remove the above meta-conversion
  892. X    
  893. X        Set the k.key[i].map[xx] values to 0x7d.  This seems to be
  894. X        the code that forces the <esc>N sequence durning translation
  895. X    */
  896. X        
  897. X    if (ioctl (tn, GIO_KEYMAP, &kt))
  898. X        ioctl_failure('r');
  899. X
  900. X    fprintf (fp, "\n\n");
  901. X    strcpy (title, "emacs normal (<esc>N<letter>) meta mapping");
  902. X    header (fp, title, also_alt_ctl);
  903. X    for (i = 0;  i < kt.n_keys;  i++)
  904. X    {
  905. X        cb = kt.key[i].map[NORMAL];            /*    base char        */
  906. X        cs = kt.key[i].map[SHIFT];            /*    shifted char    */
  907. X
  908. X        if (1)                                /*    things to ignore */
  909. X        {        /*    make ALT converssion available */
  910. X
  911. X            if ((cb >= ' '  &&  cb < 'A')  ||  (cb > 'Z'  &&  cb <= 127))
  912. X            {    kt.key[i].map[ALT] = 0x7d;
  913. X                kt.key[i].spcl |= 0x08;
  914. X            }
  915. X
  916. X            /*    make ALT-CTL conversion available  (dont include <alt><ctl><del> */
  917. X
  918. X            if (also_alt_ctl
  919. X                    &&  ((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb < 127)))
  920. X            {    kt.key[i].map[ALTCTL] = 0x7d;
  921. X                kt.key[i].spcl |= 0x02;
  922. X            }
  923. X
  924. X            /* make  ALT-SHIFT available */
  925. X
  926. X            if (((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb <= 127))
  927. X                    &&  (cs >= ' '  &&  cs <= 127))
  928. X            {    kt.key[i].map[ALTSHF] = 0x7d;
  929. X                kt.key[i].spcl |= 0x04;
  930. X            }
  931. X        
  932. X            /* make  ALT-SHIFT-CTL available */
  933. X
  934. X            if (also_alt_ctl
  935. X                    &&    ((cb >= ' '  &&  cb < 'A')  || (cb > 'Z'  &&  cb <= 127))
  936. X                    &&  (cs >= ' '  &&  cs <= 127))
  937. X            {    kt.key[i].map[ALTSHFCTL] = 0x7d;
  938. X                kt.key[i].spcl |= 0x01;
  939. X            }
  940. X        }
  941. X        fprintf (fp, "%c%c %3d   %02x   %02x", 
  942. X                cb > ' ' &&  cb < 127 ? cb : ' ',
  943. X                cs > ' ' &&  cs < 127 &&  cs != cb ? cs : ' ',
  944. X                i, 
  945. X                kt.key[i].spcl & 0x0ff, 
  946. X                kt.key[i].flgs & 0x0ff);
  947. X        for (j = 0;  j < NUM_STATES;  j++)
  948. X            fprintf (fp, "   %02x", kt.key[i].map[j]);
  949. X        fprintf (fp, "\n");
  950. X    }
  951. X
  952. X}
  953. X
  954. X/****************************************************************************
  955. X*    header ()                                                                *
  956. X*    Standard table header generation                                        *
  957. X****************************************************************************/
  958. X
  959. Xheader (fp, title, also_alt_ctl)
  960. XFILE *fp;
  961. Xchar    *title;
  962. X{    fprintf (fp, "...%s", title);
  963. X    if (also_alt_ctl == -1)
  964. X        fprintf (fp, "\n");
  965. X    else if (also_alt_ctl)
  966. X        fprintf (fp, " -- full alt/ctl\n");
  967. X    else
  968. X        fprintf (fp, " -- no alt/ctl\n");
  969. X    fprintf (fp, "                                                     alt\n");
  970. X    fprintf (fp, "                                 shif      alt  alt  shif\n");
  971. X    fprintf (fp, "  key   spcl flgs norm shif ctrl ctrl alt  shif ctrl ctrl\n");
  972. X    fprintf (fp, "------  ---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n");
  973. X}
  974. X
  975. X
  976. X/****************************************************************************
  977. X*    update_map (fp, which_map)                                                *
  978. X*    Read the specified mapping table from the map file.  Send the new map    *
  979. X*    to key keyboard driver.                                                    *
  980. X****************************************************************************/
  981. X
  982. Xupdate_map (fp, which_map)
  983. XFILE *fp;                /*    file containing keyboard maps                    */
  984. Xint     which_map;            /*    select this table from the file  (0..n)            */
  985. X{
  986. X    int    i, j, how;
  987. X    keymap_t kt;
  988. X
  989. X    /*    find the desired map in the file and read it into the keytable */
  990. X    
  991. X    if (ioctl (1, GIO_KEYMAP, &kt))                        /*    read current map        */
  992. X        ioctl_failure ('r');
  993. X
  994. X    for (i = 0;  i <= which_map;  i++)
  995. X        how = read_map (i == which_map, fp, &kt, NULL);
  996. X    if (how)
  997. X    {    fprintf (stderr, "%s: map %d not found\n", progname, which_map);
  998. X        exit (1);
  999. X    }
  1000. X    if (ioctl (1, PIO_KEYMAP, &kt))                        /*    send found map to driver */
  1001. X        ioctl_failure ('w');
  1002. X}
  1003. X
  1004. X/****************************************************************************
  1005. X*    query_map (fp)                                                            *
  1006. X*    Identifiy which table file map matches the keyboard map in use.            *
  1007. X****************************************************************************/
  1008. X
  1009. Xquery_map (fp)
  1010. XFILE *fp;                /*    file containing keyboard maps                    */
  1011. X{
  1012. X    int    i, j, k;
  1013. X    char    text[200];
  1014. X    keymap_t kt, inuse;
  1015. X    int        found;
  1016. X    int        vtlmgr;
  1017. X
  1018. X    if (ioctl (1, GIO_KEYMAP, &inuse))                    /*    read current map        */
  1019. X        ioctl_failure ('r');
  1020. X
  1021. X    vtlmgr = 0;
  1022. X    found = 0;
  1023. X    kt = inuse;
  1024. X    for (k = 0;  ;  k++)
  1025. X    {    if (read_map (1, fp, &kt, text))
  1026. X            return (found);
  1027. X        for (i = 0;  i < inuse.n_keys;  i++)
  1028. X        {    for (j = 0;  j < NUM_STATES;  j++)        /*    compare all keys    */
  1029. X            {    if (inuse.key[i].map[j] != kt.key[i].map[j])
  1030. X                {    /* detect minor mod made by vtlmgr  in line 3 for  "1!" */
  1031. X                    if (i == 2  &&  (j == ALTSHF  ||  j == ALTSHFCTL))
  1032. X                        vtlmgr = 1;
  1033. X                    else
  1034. X                        goto next_map;
  1035. X                }
  1036. X            }
  1037. X        }
  1038. X        printf ("using map %d: %s\n", k, text);
  1039. X        if (vtlmgr)
  1040. X            printf ("             (modified by vtlmgr)\n");
  1041. X        found = 1;
  1042. X        break;
  1043. Xnext_map:    ;
  1044. X    }
  1045. X    return (found);
  1046. X}
  1047. X
  1048. X/****************************************************************************
  1049. X*    read_map (fp, kt, title)                                                *
  1050. X*    Read the nextd mapping table from the map file.                            *
  1051. X****************************************************************************/
  1052. X
  1053. Xread_map (getit, fp, kt, title)
  1054. Xint            getit;        /*    1 = update kt, 0 = get title only            */
  1055. XFILE         *fp;        /*    file containing keyboard maps                */
  1056. Xkeymap_t    *kt;        /*    read structure into this                    */
  1057. Xchar        *title;        /*    read title line into this buffer            */
  1058. X{
  1059. X    int    i, j, cc;
  1060. X    char    key_line[200], *c;
  1061. X    int        a0,a1,a2,a3,a4,a5,a6,a7,a8,a9;
  1062. X    int        good_read;
  1063. X    
  1064. X    /*    find the next map in the file and read it into the keytable */
  1065. X    
  1066. X    while (good_read = (fgets (key_line, 199, fp) != NULL))
  1067. X    {    if (title != NULL  &&  strncmp (key_line, "...", 3) == 0)
  1068. X        {    strcpy (title, key_line + 3);
  1069. X            c = title;
  1070. X            while (*c)
  1071. X            {    if (*c < ' ')
  1072. X                {    *c = '\0';
  1073. X                    break;
  1074. X                }
  1075. X                c++;
  1076. X            }
  1077. X        }
  1078. X        else if (strncmp (key_line, "------  -", 8) == 0)
  1079. X            break;
  1080. X    }
  1081. X    if (good_read == 0)
  1082. X        return (-1);
  1083. X    if (strncmp (key_line, "------  -", 8) != 0)
  1084. X        bad_file ();
  1085. X
  1086. X    if (getit == 0)
  1087. X        return (1);
  1088. X    for (i = 0;  i < kt->n_keys;  i++)
  1089. X    {    if (fgets (key_line, 199, fp) == NULL)
  1090. X            bad_file ();
  1091. X        if (atoi (key_line + 2) != i)
  1092. X            bad_file ();
  1093. X        sscanf (key_line + 7, "%x %x %x %x %x %x %x %x %x %x",
  1094. X                &a0, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9);
  1095. X        kt->key[i].spcl        = a0;
  1096. X        kt->key[i].flgs        = a1;
  1097. X        kt->key[i].map[0]    = a2;
  1098. X        kt->key[i].map[1]    = a3;
  1099. X        kt->key[i].map[2]    = a4;
  1100. X        kt->key[i].map[3]    = a5;
  1101. X        kt->key[i].map[4]    = a6;
  1102. X        kt->key[i].map[5]    = a7;
  1103. X        kt->key[i].map[6]    = a8;
  1104. X        kt->key[i].map[7]    = a9;
  1105. X         
  1106. X    }
  1107. X    return (0);
  1108. X}
  1109. X
  1110. X/****************************************************************************
  1111. X*    open_file (use_file, how)                                                *
  1112. X*    Open a table file.  If there is a problem, quit now.                    *
  1113. X****************************************************************************/
  1114. X
  1115. XFILE *open_file (use_file, how)
  1116. Xchar    *use_file;
  1117. Xchar    *how;
  1118. X{    FILE    *use_fp;
  1119. X    char    *strchr();
  1120. X
  1121. X    if (*use_file == '\0')
  1122. X        strcpy (use_file, DEFAULTMAP);
  1123. X
  1124. X    if ((use_fp = fopen (use_file, how)) == NULL)
  1125. X    {    fprintf (stderr, "%s: cannot open file %s\n", progname, use_file);
  1126. X        exit (1);
  1127. X    }
  1128. X    return (use_fp);
  1129. X}
  1130. X
  1131. X/****************************************************************************
  1132. X*    bad_file ()                                                                *
  1133. X****************************************************************************/
  1134. X
  1135. Xbad_file ()
  1136. X{
  1137. X    fprintf (stderr, "%s: invalid key map file format\n", progname);
  1138. X    exit (2);
  1139. X}
  1140. X
  1141. Xioctl_failure (how)
  1142. Xint        how;
  1143. X{
  1144. X    fprintf (stderr, "%s: ioctl failure, %s\n", 
  1145. X        progname, how == 'r' ? "cannot read, possibly using X11???" : "must be root?");
  1146. X    exit (2);
  1147. X}
  1148. X
  1149. X/****************************************************************************
  1150. X*    usage ()                                                                *
  1151. X****************************************************************************/
  1152. X
  1153. Xusage ()
  1154. X{
  1155. X    printf ("Usage:     kbmap [-i] [-q] [-g] [-n n] [-d] [-e] [-m] [-1] [-t /dev/xxx] [file]\n");
  1156. X    printf ("    where:        -i      = show index of available maps\n");
  1157. X    printf ("                  -q      = identify map currenly in use\n");
  1158. X    printf ("                  -g      = generate a key map table\n");
  1159. X    printf ("                  -n n    = set keyboard to map 'n' mapping\n");
  1160. X    printf ("                  -d      = set keyboard to default mapping\n");
  1161. X    printf ("                  -e      = set keyboard to emacs mapping (<esc>N)\n");
  1162. X    printf ("                  -m      = set keyboard to emacs meta-mapping (8bit)\n");
  1163. X    printf ("                  -a      = disable <alt><ctl> & <alt><shf><ctl>\n");
  1164. X    printf ("                  -t /dev/xxx = apply map to this device (default stdin)\n");
  1165. X    printf ("                  file    = use specified key map file\n");
  1166. X    printf ("                            default = %s\n", DEFAULTMAP);
  1167. X    exit (0);
  1168. X}
  1169. END_OF_FILE
  1170. if test 18744 -ne `wc -c <'kbmap.c'`; then
  1171.     echo shar: \"'kbmap.c'\" unpacked with wrong size!
  1172. fi
  1173. # end of 'kbmap.c'
  1174. fi
  1175. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  1176.   echo shar: Will not clobber existing file \"'Makefile'\"
  1177. else
  1178. echo shar: Extracting \"'Makefile'\" \(509 characters\)
  1179. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  1180. X#        k b m a p 
  1181. X#
  1182. X#    change the keyboard scan code mapping for AT&T unix SysV 3.2.2
  1183. X#
  1184. X# Select your compiler and options
  1185. X
  1186. XCC=gcc
  1187. XCFLAGS=-traditional
  1188. X
  1189. X# CC=cc
  1190. X# CFLAGS=
  1191. X
  1192. X# Set BINDIR as desired.  Provide a name for the default keyboard map table.
  1193. X
  1194. XBINDIR = /local/bin
  1195. XMAPTABLE = /local/lib/kbmap.table
  1196. X
  1197. Xall:
  1198. X    $(CC) $(CFLAGS) -DDEFAULTMAP="\"$(MAPTABLE)"\" kbmap.c -o kbmap
  1199. X
  1200. Xinstall:
  1201. X    strip kbmap
  1202. X    cp kbmap $(BINDIR)
  1203. X
  1204. Xshar:
  1205. X    shar Readme kbmap.doc kbmap.1 kbmap.c Makefile > kbmap.shar
  1206. X
  1207. Xclean:
  1208. X    rm -f *.o *.B *.BAK
  1209. END_OF_FILE
  1210. if test 509 -ne `wc -c <'Makefile'`; then
  1211.     echo shar: \"'Makefile'\" unpacked with wrong size!
  1212. fi
  1213. # end of 'Makefile'
  1214. fi
  1215. echo shar: End of shell archive.
  1216. exit 0
  1217.  
  1218.  
  1219.